import json

from py2neo import Graph

# 数据库地址
sdp_uri = "http://192.168.2.239:7687"
self_uri = "bolt://192.168.70.129:7687"
# 用户名密码
sdp_username = "neo4j"
sdp_password = "sdpneo4j"

pkg_all_file_path = 'pkg/pkgs_all.json'


def get_graph(uri=self_uri, db_username=sdp_username, db_password=sdp_password):
    graph = Graph(uri, auth=(db_username, db_password))
    return graph


def load_pkgs(file_path=pkg_all_file_path):
    with open(file_path, 'r', encoding='utf8') as fp:
        return json.load(fp)


# 获取条目信息，没有条目则返回""
def get_value(package_dict, key_str):
    try:
        return package_dict[key_str]
    except KeyError:
        return ""
